/**
 * 
 */
package tree;

/**
 * @author Michael
 * 
 */
public class Node<T extends Comparable<? super T>> {

	public T value = null;
	public Node<T> left = null;
	public Node<T> right = null;
	public Node<T> parent = null;
	public boolean isBalanced = true;
	public int height = 1;
	public boolean isSentinel = false;

	public Node(T value, Node<T> left, Node<T> right) {
		this.value = value;
		this.left = left;
		this.right = right;
	}

	public Node(T value) {
		this.value = value;
	}

	public Node(T value, Node<T> parent) {
		this.value = value;
		this.parent = parent;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (!(o instanceof Node)) {
			return false;
		}
		@SuppressWarnings("unchecked")
		Node<T> node = (Node<T>) o;
		return this.value.equals(node.value);
	}

	@Override
	public int hashCode() {
		int result = 17;
		result = 31 * result + this.value.hashCode();
		return result;
	}

	@Override
	public String toString() {
		return value.toString();
	}

	public static <T extends Comparable<? super T>> Node<T> getSentinel(T value) {
		Node<T> node = new Node<T>(value, null, null);
		node.isSentinel = true;
		return node;
	}
}
